package com.example.xd.yunshixun;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.chinamobile.ysx.YSXInstantMeetingOptions;
import com.chinamobile.ysx.YSXMeetingError;
import com.chinamobile.ysx.YSXMeetingService;
import com.chinamobile.ysx.YSXMeetingSettingsHelper;
import com.chinamobile.ysx.YSXMessageListener;
import com.chinamobile.ysx.YSXSdk;

public class StartMeetingActivity extends AppCompatActivity implements View.OnClickListener, YSXMessageListener {

    private EditText mEt_meet_id;
    private EditText mEt_meet_num;
    private EditText mEt_meet_pwd;
    private EditText mEt_meet_type;
    private EditText mEt_meet_topic;
    private CheckBox mChb_open_hole_meetingVideo;
    private CheckBox mChb_open_mic;
    private CheckBox mChb_open_video;
    private CheckBox mChb_customize_video;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_meeting);

        mEt_meet_id = findViewById(R.id.et_meet_id);
        mEt_meet_num = findViewById(R.id.et_meet_num);
        mEt_meet_pwd = findViewById(R.id.et_meet_pwd);
        mEt_meet_type = findViewById(R.id.et_meet_type);
        mEt_meet_topic = findViewById(R.id.et_meet_topic);

        mChb_open_hole_meetingVideo = findViewById(R.id.chb_open_hole_meetingVideo);
        mChb_open_mic = findViewById(R.id.chb_open_mic);
        mChb_open_video = findViewById(R.id.chb_open_video);
        mChb_customize_video = findViewById(R.id.chb_customize_video);

        findViewById(R.id.btn_start_meeting).setOnClickListener(this);

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_start_meeting:
                startIMMeeting();
                break;
        }
    }

    private void startIMMeeting() {
        YSXSdk instance = YSXSdk.getInstance();
        if (!instance.isInitialized()) {
            Toast.makeText(this, "sdk未初始化", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!instance.isLoggedIn()) {
            Toast.makeText(this, "请登录", Toast.LENGTH_SHORT).show();
            return;
        }
        //开启即时会议的各项设置
        YSXInstantMeetingOptions opts = new YSXInstantMeetingOptions();
        opts.no_video = false;//是否自动连接视频 true为不自动连接
        String topic = mEt_meet_topic.getText().toString();
        String Agenda = "";
        String participants = "";//参会人员的id用,分割


        YSXMeetingSettingsHelper ysxMeetingSettingsHelper = instance.getMeetingSettingsHelper();
//设置自动连接音频  true 自动连接 false  不自动连接
        ysxMeetingSettingsHelper.setAutoConnectVoIPWhenJoinMeeting(true);
//入会时开启麦克风
        ysxMeetingSettingsHelper.setMuteMyMicrophoneWhenJoinMeeting(mChb_open_mic.isChecked());
//入会时开启视频
        ysxMeetingSettingsHelper.setTurnOffMyVideoWhenJoinMeeting(mChb_open_video.isChecked());

        YSXMeetingService meetingservice = instance.getMeetingService();
        if (TextUtils.isEmpty(topic)) {
            Toast.makeText(this, "会议主题不能为空", Toast.LENGTH_SHORT).show();
        } else {
            meetingservice.startInstantMeeting(StartMeetingActivity.this, topic, Agenda, participants, opts, this);
        }

    }

    @Override
    public void onCallBack(final int i, final String s) {
        Log.i("xd-------------", i + "---" + s);
    }
}
